package maskWork;

import java.util.Random;

public class Maintest {
	
	public static void main(String[] args) {
		
		System.out.println("本机可用的线程数:"+Runtime.getRuntime().availableProcessors());
		
		//创建一个主线程,10work线程
		Master master = new Master(new Work(), Runtime.getRuntime().availableProcessors());
		
		//扔进去100个任务
		Random random = new Random();
		for (int i = 1; i < 100; i++) {
			
			Task task = new Task();
			task.setId(i);
			task.setName("task_"+i);
			task.setPrice(random.nextInt(1000));
			
			master.submit(task);
		}
		
		//启动线程处理
		master.workAll();
		
		long start = System.currentTimeMillis();
		while (true) {
			boolean tag = master.isComplete();
			if(tag){
				long end = System.currentTimeMillis() - start;
				int result = master.getResult();
				System.out.println("执行结果: "+result+",耗时："+end);
				break;
			}
		}
	}

}
